#ifndef MENUINGAME_H
#define MENUINGAME_H

#include "MenuState.h"
#include "ReplayState.h"
#include "MenuOptions.h"

typedef enum {
    SM_LEVEL_COMPLETE,
    SM_GAME_OVER,
    SM_FINAL_LEVEL_COMPLETE,
    SM_COMPLETED,
    QP_LEVEL_COMPLETE,
    QP_FAILED,
    LOAD_REPLAY,
    LOAD,
    PAUSE
} LayoutType;

typedef enum {
    lsNORMAL,
    lsLOADING,
    lsLOADED,
    lsREPLAY_LEVEL,
    lsNEXT_LEVEL,
    lsPLAY_REPLAY,
	lsRESUME,
    lsQUIT
} LayoutState;

/*
 * Generates all of the in game menu screens
 */
class MenuInGame : public MenuState, public ReplayState
{
    public:
        MenuInGame(void) { USE_GHOST = false; }
	   ~MenuInGame(void) {}
	   
	    bool USE_GHOST;
	    std::string getGhostReplay();

        void getStatePointers();
	    void enter(void);
	    void exit(void);

        bool keyPressed(const OIS::KeyEvent &);
        bool frameStarted(const Ogre::FrameEvent &evt);
        bool frameEnded(const Ogre::FrameEvent &evt);
        
        // extended from ReplayState
        void stopPlaying();
        
        void setLayout(LayoutType type) { layoutType = type; }
        void setupSMLevelCompleteEndGame();
        void setupSMLevelComplete();
        void setupSMEnd();
        void setupSMGameOver();
        void setupSMCompleted();
        void setupLevelComplete();
        void setupQPLevelComplete();
        void setupQPFailed();
        void setupLoadingReplay();
        void setupLoading();
        void setupLoaded();
        void setupPause();

        LayoutState getState() { return currentState; };
        void resetState() { currentState = lsNORMAL; }
        void setState(LayoutState newState) { currentState = newState; };
		Ogre::String formatTime(int timeLimit);
		bool isEditboxActive();

        ///////////////// Events handlers //////////////////
        
        // Use Ghost
        bool clickGhostMode(const CEGUI::EventArgs &e);
        
        // Play
        bool clickPlay(const CEGUI::EventArgs &e);
        bool hoverPlay(const CEGUI::EventArgs &e);
        bool offPlay(const CEGUI::EventArgs &e);
        
        // Submit score
		bool clickSubmitScore();
        bool clickSubmitScore(const CEGUI::EventArgs &e);
        bool hoverSubmitScore(const CEGUI::EventArgs &e);
        bool offSubmitScore(const CEGUI::EventArgs &e);
        
        // Quit
        bool clickQuit(const CEGUI::EventArgs &e);
        bool hoverQuit(const CEGUI::EventArgs &e);
        bool offQuit(const CEGUI::EventArgs &e);
        
        // Continue
        bool clickContinue(const CEGUI::EventArgs &e);
        bool hoverContinue(const CEGUI::EventArgs &e);
        bool offContinue(const CEGUI::EventArgs &e);
        
        // Watch Replay
        bool clickWatchReplay(const CEGUI::EventArgs &e);
        bool hoverWatchReplay(const CEGUI::EventArgs &e);
        bool offWatchReplay(const CEGUI::EventArgs &e);
        
        // Next Level
        bool clickNextLevel(const CEGUI::EventArgs &e);
        bool hoverNextLevel(const CEGUI::EventArgs &e);
        bool offNextLevel(const CEGUI::EventArgs &e);
        
		// Try Again
		bool clickTryAgain(const CEGUI::EventArgs &e);
		bool hoverTryAgain(const CEGUI::EventArgs &e);
		bool offTryAgain(const CEGUI::EventArgs &e);

		// Replay Level
        bool clickReplayLevel(const CEGUI::EventArgs &e);
        bool hoverReplayLevel(const CEGUI::EventArgs &e);
        bool offReplayLevel(const CEGUI::EventArgs &e);

		// Resume
        bool clickResume(const CEGUI::EventArgs &e);
        bool hoverResume(const CEGUI::EventArgs &e);
        bool offResume(const CEGUI::EventArgs &e);

		// Options
        bool clickOptions(const CEGUI::EventArgs &e);
        bool hoverOptions(const CEGUI::EventArgs &e);
        bool offOptions(const CEGUI::EventArgs &e);
        
    private:
        LayoutType layoutType;
        CEGUI::Window* layoutHolder;
        LayoutState currentState;
        bool playReplay, loadingReplay;
		bool highScoreAchieved;
		MenuOptions *options;
		int highScoreHold;
};

#endif

